import React, {Component} from 'react'
import RootToast from '../components/CustomToast'
import {View, Text, Platform, StyleSheet} from 'react-native'
import {deviceInfo} from '../utils/deviceInfo'

const Toast = {

    toast: null,

    show: (msg) => {
        this.toast = RootToast.show(msg, {
            position: 0,
            duration: 1200
        })
    },

    showLong: (msg) => {
        this.toast = RootToast.show(msg, {
            position: 0,
            duration: 2000
        })
    },

    showSuccess: (msg, options) => {
        let toast = RootToast.show(
            msg,{
                position:RootToast.positions.TOP,
                duration:1200,
                type:'success',
                backgroundColor:'#5db85c',
                containerStyle:{width:deviceInfo.deviceWidth, flexDirection:'row', justifyContent: 'center',alignItems: 'center', borderRadius:0},
                textStyle:{marginLeft:10,},
                opacity:1,
                ...options,
            })
        // setTimeout(function () {
        //     RootToast.hide(toast)
        //     typeof options === 'function' ? options && options(): null
        // }, 2000)
    },
    //暂停使用
    showLongSuccess: (msg, options) => {
        let toast = RootToast.show(
                msg, {
                duration: 2000,
                position: RootToast.positions.CENTER,
                ...options,
            })
        setTimeout(function () {
            RootToast.hide(toast)
            typeof options === 'function' ? options && options(): null
        }, 2500)
    },

    showWarning: (msg, options) => {
        let toast = RootToast.show(
                msg, {
                position:RootToast.positions.TOP,
                duration:1200,
                type:'info',
                backgroundColor:'#fa0',
                containerStyle:{width:deviceInfo.deviceWidth, flexDirection:'row', justifyContent: 'center',alignItems: 'center', borderRadius:0},
                textStyle:{marginLeft:10,},
                opacity:1,
                ...options,
            })
        // setTimeout(function () {
        //     RootToast.hide(toast)
        // }, RootToast.durations.SHORT + 500)
    },

    showError: (msg, options) => {
        let toast = RootToast.show(
                msg, {
                position:RootToast.positions.TOP,
                duration:1200,
                type:'fail',
                backgroundColor:'#f00',
                containerStyle:{width:deviceInfo.deviceWidth, flexDirection:'row', justifyContent: 'center',alignItems: 'center', borderRadius:0},
                textStyle:{marginLeft:10,},
                opacity:1,
                ...options,
            })
        // setTimeout(function () {
        //     RootToast.hide(toast)
        // }, RootToast.durations.SHORT + 500)
    },

    showLoading: (msg, options) => {
        let toast = RootToast.show(
            msg,{
                position:RootToast.positions.CENTER,
                duration:1200,
                type:'loading',
                ...options,
            }
        )
    }
}

var styles = StyleSheet.create({
    container: {
        width: 140,
        height: 120,
        alignItems: 'center',
        justifyContent: 'center',
    },
    message: {
        color: '#fff',
        marginTop: 10,
        textAlign: 'center',
        lineHeight: 20,
    }
})

export default Toast